package com.zlx.guguanjia.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zlx.guguanjia.entity.AppVersion;
import com.zlx.guguanjia.entity.Result;
import com.zlx.guguanjia.mapper.AppVersionMapper;
import com.zlx.guguanjia.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Author 周罗校
 * @Description
 * @ClassName AppVersionServiceImpl
 * @date 2020.10.22 15:24:54
 * 该版权归周罗校所有，最终解释权以官方为准
 */

//开启事务
@Transactional
@Service
public class AppVersionServiceImpl extends BaseServiceImpl<AppVersion, Long> implements AppVersionService {
    @Autowired
    private AppVersionMapper mapper;

    /***
     * @Author 周罗校
     * @Description 分页工具
     * @Param [start, pageSize]
     * @return com.github.pagehelper.PageInfo<com.zlx.guguanjia.entity.AppVersion>
     * @Date 2020.10.23 10:41:13
     **/
    @Override
    public PageInfo<AppVersion> selectPage(int start, int pageSize) {
        PageHelper.startPage(start, pageSize);
        AppVersion app = new AppVersion();
        app.setDelFlag("0");
//        int i=1/0;
        List<AppVersion> appVersions = mapper.select(app);
        return new PageInfo<AppVersion>(appVersions);
    }
    /**
     * @Author 周罗校
     * @Description 逻辑删除
     * @Param [id]
     * @return int
     * @Date 2020.10.23 15:08:10
     **/
    @Override
    public int deleteAppVersionById(Long id) {
        AppVersion app = new AppVersion();
        //设置为1，标志已删除
        app.setDelFlag("1");
        app.setId(id);
        return mapper.updateByPrimaryKeySelective(app);
    }


    /***
     * @Author 周罗校
     * @Description 插入操作
     * @Param [appVersion]
     * @return int
     * @Date 2020.10.23 17:17:40
     **/
    @Override
    public int insertAppVersion(AppVersion appVersion) {
        //标记为没有删除
        appVersion.setDelFlag("0");
        //创建时间，数据库非空字段
        appVersion.setCreateDate(new Date());
        //更新时间
        appVersion.setUpdateDate(new Date());
        //返回分页数据
        return mapper.insertSelective(appVersion);
    }
}
